############################################################################
CROSS_COMPILE = 
AS			  = $(CROSS_COMPILE)as
LD			  = $(CROSS_COMPILE)ld
CC			  = $(CROSS_COMPILE)gcc
CPP			  = $(CC) -E
AR			  = $(CROSS_COMPILE)ar
NM			  = $(CROSS_COMPILE)nm
STRIP		  = $(CROSS_COMPILE)strip
OBJCOPY		  = $(CROSS_COMPILE)objcopy
OBJDUMP		  = $(CROSS_COMPILE)objdump

export AS LD CC CPP AR NM
export STRIP OBJCOPY OBJDUMP
############################################################################

CFLAGS := -O2 -g -Wall -Wshadow -Wundef -Wmissing-prototypes
CFLAGS += -I./inc/ 
CFLAGS += -I/usr/include/
CFLAGS += -I/usr/include/SDL2/
CFLAGS += -I/usr/local/include/SDL2/
CFLAGS += -I/usr/include/freetype2/

CFLAGS += -I./library/lib_gui/
CFLAGS += -I./library/lib_cjson/

CFLAGS += -Iapplication/src/
CFLAGS += -Iapplication/src/ui_page/base_page/
CFLAGS += -Iapplication/src/ui_page/com_page/
CFLAGS += -Iapplication/src/ui_page/sys_font/
CFLAGS += -Iapplication/src/ui_page/root/
CFLAGS += -Iapplication/src/ui_page/dev_page/
CFLAGS += -Iapplication/src/ui_page/home_page/
CFLAGS += -Iapplication/src/ui_page/setting_page/
CFLAGS += -Iapplication/src/ui_page/page_manager/
CFLAGS += -Iapplication/src/ui_page/popup_win_page/
CFLAGS += -Iapplication/src/ui_page/res/
CFLAGS += -Iapplication/src/ui_page/first_time_page/
CFLAGS += -Iapplication/src/ui_page/collection_view/
CFLAGS += -Iapplication/src/platform/
CFLAGS += -Iapplication/src/com_api/
CFLAGS += -Iapplication/src/com_api/


CPPFLAGS := -I  /usr/local/include/opencv4/
############################################################################

LDFLAGS := -ldl -lm -lpthread
LDFLAGS += -L/usr/lib
LDFLAGS += -L/usr/local/lib
LDFLAGS += -lfreetype
LDFLAGS += -lSDL2
LDFLAGS += -lcurl

export CFLAGS LDFLAGS
############################################################################

PROJECT_PATH := $(shell pwd)
export PROJECT_PATH

OUTPUT_DIR := $(PROJECT_PATH)/output

PROJECT_NAME := simulvgl
############################################################################
############################################################################
#找到当前目录下的所有C文件

CSRCS += $(shell find $(PROJECT_PATH) -name '*.c')
############################################################################
#将.c文件替换成.o文件
CXX_OBJCTS = $(patsubst  %.c, $(OUTPUT_DIR)/%.o, $(notdir $(CSRCS)))
SRC_C_DEPS = $(patsubst  %.c, $(O).%.o.d, $(CSRCS))
############################################################################
SOURSE_DIR = $(dir $(CSRCS))
vpath %.c $(SOURSE_DIR)
############################################################################

$(OUTPUT_DIR)/%.o: %.c
	$(CC) $< -c -MMD -o $@ $(CFLAGS)
	#@echo "build $<"
 
all: mk_output $(CXX_OBJCTS)
	@$(CC) -o $(PROJECT_NAME) $(CXX_OBJCTS) $(LDFLAGS)
	$(info >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>)
	$(info ............build succeed...............)
	$(info >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>)
############################################################################
clean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")
	rm -f $(PROJECT_NAME)

distclean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")
	rm -f $(PROJECT_NAME)
mk_output:
	mkdir -p $(OUTPUT_DIR)
debug:
	@echo "CSRCS=$(CSRCS)"
	@echo "CXX_OBJCTS=$(CXX_OBJCTS)"
	@echo "SRC_C_DEPS=$(SRC_C_DEPS)"
############################################################################
FORCE:
.PHONY: FORCE
-include $(OUTPUT_DIR)/*.d

	